from brownie import SimpleStorage, network, accounts, config;

# 根据部署环境确定使用的账号
def get_env():
    if (network.show_active() == 'development'):
        return accounts[0];
    else:
        return accounts.add(config['wallets']['from_key']);

def main():
    # -1取到的是最新的合约地址
    print(SimpleStorage[-1]);
    simple_storage = SimpleStorage[-1];
    fav_num = simple_storage.retrieve();
    print(f'favourite number is {fav_num}');
    # 更新数据，对于更改区块链数据的操作，需要一个包含from字段的dict来指明是谁发起了这笔交易
    transaction = simple_storage.store(777, {'from': get_env()});
    # 等待一个区块
    transaction.wait(1);
    updated_num = simple_storage.retrieve();
    print(f'updated num is {updated_num}');
    